package com.dy.dynotinstalled

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.dy.dynotinstalled.room.NotDoorInformation
import com.dy.dynotinstalled.room.NotDoorInformationViewModel

/**
 * @author Li Xuyang
 * @date : 2019/11/6 22:55
 */
class DetailsActivity : AppCompatActivity() {
    lateinit var doorInformationViewModel: NotDoorInformationViewModel
    lateinit var myRecyclerView: RecyclerView
    lateinit var doorAdapter: DoorAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.acticity_details)

        doorInformationViewModel =
            ViewModelProviders.of(this).get(NotDoorInformationViewModel::class.java!!)
        myRecyclerView = this.findViewById(R.id.recyclerView)
        myRecyclerView.layoutManager = LinearLayoutManager(this)


        doorAdapter = DoorAdapter(doorInformationViewModel)


        doorInformationViewModel.getAllDoorInformationRepositoryLive()
            .observe(this, Observer<List<Any>> { doorInformation ->
                val temp = doorAdapter.getItemCount()
                doorAdapter.setAllNotDoorInformation(doorInformation as MutableList<NotDoorInformation>?)

                myRecyclerView.setAdapter(doorAdapter)

                if (temp != doorInformation.size) {
                    doorAdapter.notifyDataSetChanged()
                }
            })
    }
}
